<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    :modal="true"
    :appendToBody="true"
    width="70%"
    v-dialog-drag
    :close-on-click-modal="false"
    top="5vh"
    class='dialog-report-dis'
    :loading="saveloading"
    @close="handleClose()"
    @open="handleOpen()"
  >
    <PartitionTitle title="异常基本信息"></PartitionTitle>
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="110px">
      <el-form-item label="异常名称" prop="orderName">
        <el-input type="text" v-model="form.orderName" placeholder="请输入异常名称" :disabled="mode == 'approval'"></el-input>
      </el-form-item>

      <el-form-item label="异常等级" prop="abnormalLevelCode">
        <el-select
          placeholder="请选择异常等级"
          clearable
          v-model="form.abnormalLevelCode"
          size="small"
          :disabled="mode == 'approval'"
        >
          <el-option
            v-for="item in dict.AbnormalLevel"
            :key="item.codevalue"
            :label="item.codename"
            :value="item.codevalue"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-row type="flex" style="width:100%">
        <el-col :span="24">
          <el-form-item label="异常分类" prop="abnormalTypeCode">
            <el-select
              placeholder="请选择异常分类"
              clearable
              v-model="form.abnormalTypeCode"
              size="small"
              disabled
            >
              <el-option
                v-for="item in dict.AbnormalType"
                :key="item.codevalue"
                :label="item.codename"
                :value="item.codevalue"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex" style="width:100%">
        <el-col :span="12">
          <el-form-item label="关联指标" prop='indexCode' style="width:98%">
            <el-input type="text" v-model="form.indexName" placeholder="请选择关联指标" readonly :disabled="mode == 'approval'">
              <el-button slot="append" icon="el-icon-search" @click="openIndexDialog" readonly :disabled="mode == 'approval'"></el-button>
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="指标类型" prop='indexType' v-if='form.indexCode' style="width:100%">
            <el-input type="text" v-model="form.indexTypeName" :disabled="!!indexItem.indexType || mode == 'approval'"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="所属工厂" prop='factoryDeptCode'>
        <el-select
          :disabled="!!indexItem.factoryDeptCode || mode == 'approval'"
          v-model="form.factoryDeptCode"
          placeholder="请选择工厂"
          size="small"
          clearable
          @change="handleFactory"
        >
          <el-option
            v-for="item in allList"
            :key="item.factoryDeptCode"
            :label="item.factoryName"
            :value="item.factoryDeptCode"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="所属车间" prop='workshopCode'>
        <el-select
          :disabled="!!indexItem.workshopCode || mode == 'approval'"
          v-model="form.workshopCode"
          placeholder="请选择车间"
          size="small"
          clearable
          @change="handleWorkshop"
        >
          <el-option
            v-for="item in workshopList"
            :key="item.workshopCode"
            :label="item.workshopName"
            :value="item.workshopCode"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="所属产线" prop='erpProductionLineCode'>
        <el-select
          :disabled="!!indexItem.erpProductionLineCode || mode == 'approval'"
          v-model="form.erpProductionLineCode"
          placeholder="请选择产线"
          size="small"
          clearable
          @change="handleLine"
        >
          <el-option
            v-for="item in lineList"
            :key="item.lineCode"
            :label="item.lineName"
            :value="item.lineCode"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="关联设备" prop='equipmentName'>
        <el-input type="text" v-model="form.equipmentName" placeholder="请选择上关联设备" readonly :disabled="!(form.factoryDeptCode && form.workshopCode) || !!indexItem.equipmentName || mode == 'approval'">
          <el-button slot="append" icon="el-icon-search" @click="openEquipDialog" :disabled="!(form.factoryDeptCode && form.workshopCode) || !!indexItem.equipmentName || mode == 'approval'"></el-button>
        </el-input>
      </el-form-item>

      <!-- 上报 -->
      <template v-if='mode == "report" || mode == "approval"'>
        <el-form-item label="上报人" prop='reportName'>
          <el-input type="text" v-model="form.reportName" disabled></el-input>
        </el-form-item>

        <el-form-item label="审核人" prop='checkName'>
          <el-input type="text" v-model="form.checkName" placeholder="请选择审核人" readonly :disabled="mode == 'approval'">
            <el-button slot="append" icon="el-icon-search" @click="openUserDialog('checkName')" :disabled="mode == 'approval'"></el-button>
          </el-input>
        </el-form-item>

        <el-form-item label="上报时间" prop='reportDate' v-if='mode == "approval"'>
          <el-input type="text" v-model="form.reportDate" :disabled="mode == 'approval'"></el-input>
        </el-form-item>
      </template>

      <!-- 下发 -->
      <template v-if='mode == "distribute"'>
        <el-form-item label="下发人" prop='reportName'>
          <el-input type="text" v-model="form.reportName" disabled></el-input>
        </el-form-item>

        <el-form-item label="责任人" prop='processedName'>
          <el-input type="text" v-model="form.processedName" placeholder="请选择责任人" readonly :disabled="mode == 'approval'">
            <el-button slot="append" icon="el-icon-search" @click="openUserDialog('processedName')" :disabled="mode == 'approval'"></el-button>
          </el-input>
        </el-form-item>
      </template>

      <el-form-item label="异常描述" prop='abnormalDes' style="width:100%">
        <el-input
          :disabled="mode == 'approval'"
          type="textarea"
          :autosize="{ minRows: 2}"
          maxlength="150"
          show-word-limit
          placeholder="请输入异常描述"
          v-model="form.abnormalDes">
        </el-input>
      </el-form-item>

      <el-form-item label="附件" style="width:100%">
        <el-upload
          :disabled="mode == 'approval'"
          class="upload-demo"
          :action="uploadUrl"
          :headers="{Authorization:token}"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :before-upload='beforeAvatarUpload'
          :on-success='handleSuccess'
          :accept="acceptFile"
          multiple
          :limit="10"
          :on-exceed="handleExceed"
          :file-list="fileList">
          <el-button size="small" type="primary" :disabled="mode == 'approval'">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">请上传大小不超过 5MB 格式为 jpg/png/gif/pdf/doc/docx/xls/xlsx/ppt/pptx/jpeg/zip 的文件，最多10个。</div>
        </el-upload>
      </el-form-item>

      <!-- 上报异常审核 -->
      <template v-if='mode == "approval"'>
        <PartitionTitle title="异常上报反馈"></PartitionTitle>
        <el-form-item label="反馈" style="width:100%" prop='checkDes'>
          <el-input
            type="textarea"
            :autosize="{ minRows: 2}"
            maxlength="150"
            show-word-limit
            placeholder="请输入异常描述"
            v-model="form.checkDes">
          </el-input>
        </el-form-item>
      </template>
    </el-form>

    <span slot="footer" class="dialog-footer" v-if='mode == "approval"'>
      <el-button  @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" plain @click="handleIgnore" >忽 略</el-button>
      <el-button type="primary" @click="convertToAbnormal">转为 异常</el-button>
    </span>

    <span slot="footer" class="dialog-footer" v-else>
      <el-button  @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
    <change-to-abnormal
      :visible.sync="detailDialog.visible"
      :row="detailDialog.row"
      @submit-change="callbackDialog"/>
    <userList
      :visibles.sync="userDialog.visible"
      :multiple='mode == "distribute"'
      :defaultValues="userDialog.defaulSelectUsers"
      :branchinnercode="userDialog.branchinnercode"
      @closeDialog="closeUserDialog">
    </userList>
    <!-- 设备列表 -->
    <equipList
      :visible.sync="equipListDialog.visible"
      :defaultValues="equipListDialog.defaultValues"
      :defaultSearch="{
        factoryDeptCode: form.factoryDeptCode,
        workshopCode: form.workshopCode,
        workshopId:form.workshopId,
        lineId: form.lineId
      }"
      :disabledSearch="{
        factory: !!form.factoryDeptCode,
        workshop: !!form.workshopCode,
        line: !!form.lineId
      }"
      :multiple="false"
      @closeDialog="closeEquipDialog"
    ></equipList>

    <index-List
      :visible.sync="indexDialog.visible"
      :defaultValues="indexDialog.defaultValues"
      :defaultSearch="{
        factoryDeptCode: form.factoryDeptCode,
        workshopId: form.workshopId,
        workshopCode: form.workshopCode,
        lineId: form.lineId
      }"
      :multiple="false"
      @closeDialog="closeIndexDialog"
    />
  </el-dialog>
</template>
<script>
  import axios from 'axios'
  import { getToken } from '@/utils/auth'
  import service from "@//utils/request";
  import { GEN_SERVER } from '@/config/baseUrl'
  import { downloadFile } from '@/utils/file'
  import { parseTime } from '@/utils/eam'
  import { fileTypes } from '@/utils/file'
  import IndexList from "@/views/components/indexList";
  import { distributeIgnore,abnormalAddOrUpdate } from "@/api/exceptionMgmt/distribute";
  import {validLetterDigit,validLetterDigitUnderline,patterns} from "@/utils/validate";
  import {getIndexConfigDetail} from "@/api/indexMgmt/configuration";
  import organizationCascader from "@/views/components/organizationCascader";
  import changeToAbnormal from "../components/changeToAbnormal";
  import equipList from "@/views/components/equipList";
  import { mapGetters } from "vuex";
export default {
  components:{organizationCascader,changeToAbnormal,equipList,IndexList},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: null
    },

    mode:{
      type: String,
      default: null
    },
    title:{
      type: String,
      default: null
    }
  },
  dicts: ["indexType", "AbnormalType", "AbnormalLevel"],
  data() {
    return {
      form: {
        orderName:null,
        abnormalLevelCode:null,
        abnormalTypeCode:null,
        indexCode:null,
        indexType:null,
        indexTypeName:null,
        factoryDeptCode:null,
        workshopCode:null,
        erpProductionLineCode:null,
        equipmentCode:null,
        equipmentName:null,
        reportName:null,
        checkName:null,
        checkUserName :null,
        reportUserName:null,
        processedUserName:null,
        processedName:null,
        checkDes:null,
        fileIds:[]
      },
      rules: {
        orderName: [
          { required: true, message: "请输入异常名称" },
          { max: 32, message: "不能超过30个字符", trigger: "blur" },
        ],
        abnormalLevelCode: [
          { required: true, message: "请选择异常等级", trigger: "change" },
        ],
        abnormalTypeCode:[
          { required: true, message: "请选择异常分类", trigger: "change" }
        ],
        targetType:[
          { required: true, message: "请选择指标类型", trigger: "change" }
        ],
        factoryDeptCode: [
          { required: true, message: "请选择所属工厂", trigger: "change" },
        ],
        workshopCode: [
          { required: true, message: "请选择所属车间", trigger: "change" },
        ],
        reportName: [
          { required: true, message: this.mode == "distribute" ? "请选择下发人" :"请选择上报人", trigger: "change" },
        ],
        checkName: [
          { required: true, message: "请选择审核人", trigger: "change" },
        ],
        processedName: [
          { required: true, message: "请选择责任人", trigger: "change" },
        ],
        abnormalDes:[
          { required: true, message: "请输入异常描述", trigger: "blur" },
        ],
        checkDes:[
          { required: true, message: "请输入异常反馈", trigger: "blur" },
        ]
      },
      indexItem:{
        indexType:null,
        factoryDeptCode:null,
        workshopCode:null,
        erpProductionLineCode:null,
        equipmentName:null
      },
      disabledUser:[],
      workshopList:[],
      lineList:[],
      fileTypes,
      fileList:[],
      userDialog: {
        visible: false,
        defaulSelectUsers:[],
        key:null
      },
      detailDialog:{
        visible: false,
        row:null
      },
      clearData:{
        factory:true,
        workshop:true,
        line:true
      },
      indexDialog: {
        visible: false,
        defaultValues: [],
      },
      // 设备选择弹框
      equipListDialog: {
        visible: false,
        defaultValues: [],
      },
      saveloading: false,
      deviceId:null
    };
  },
  computed: {
    dialogVisible: {
      set(val) {
        this.$emit("update:visible", val)
      },
      get() {
        return this.visible
      }
    },
    ...mapGetters([
      'realname',
      'name',
      'baseDeptId',
      'allList'
    ]),
    indexTypeDictMap() {
      return this.dictToMap(this.dict.indexType);
    },
    uploadUrl(){
      return service.baseURL + GEN_SERVER['form-server'] + '/refine/report/upload'
    },
    token() {
      return 'Bearer ' + getToken()
    },
    acceptFile(){
      return Object.values(this.fileTypes).join(",")
    }
  },
  created(){
  },
  methods: {
    handleClose() {
      this.saveloading = false;
      this.resetFormData();
    },
    handleOpen() {
      this.resetFormData();
      if(this?.row){//审核
        this.form = Object.assign({},this.row);
        const {factoryDeptCode,workshopCode,erpProductionLineCode} = this.form
        this.indexItem.factoryDeptCode = factoryDeptCode;
        this.indexItem.workshopCode = workshopCode;
        this.indexItem.erpProductionLineCode = erpProductionLineCode;
        if(this.form?.indexCode){
          this.getIndexDetail()
        }
        if(this.form.files?.length){
          this.fileList = this.form.files.map(item => {
            return {
              name: item?.fileName,
              fileType:item.fileType,
              response: {
                data: item.id,
                code: 200
              }
            };
          });
        }
      }
      else{
        const result = this.getOwnFirstLine()
        this.form.factoryDeptCode = result[0]?.factoryDeptCode;
        this.form.factoryDeptId = result[0]?.factoryDeptId;
        this.form.workshopCode = result[1]?.workshopCode;
        this.form.workshopId = result[1]?.workshopId;
        this.form.lineId = result[2]?.lineId;
        this.form.erpProductionLineCode = result[2]?.lineCode;
        this.form.abnormalTypeCode = "AbnormalManual";
      }
      if(this.form?.factoryDeptCode){
        this.handleFactory(this.form.factoryDeptCode,"init")
      }
      if(this.form?.workshopCode){
        this.handleWorkshop(this.form.workshopCode,"init")
      }
      this.form.reportName = this.realname;
      this.form.reportUserName = this.name;
    },

    getIndexDetail(){
      getIndexConfigDetail(this.form?.indexCode)
      .then(res=>{
        if (res.code == 200 && res.data) {
          const indexItem = res.data;
          const {indexType} = indexItem?.indexMetaDto;
          const {indexConfigName,
            factoryDeptCode,factoryDeptId,
            workshopCode,workshopId,lineCode,
            lineId,equipCode,equipName,id
          } = indexItem;
          this.form.indexCode = id;
          this.form.indexName = indexConfigName;
          this.form.indexType = indexType;
          this.$nextTick(()=>{
            this.$set(this.form,"indexTypeName",indexType ? this.indexTypeDictMap[indexType] : null)
          })
          this.form.factoryDeptCode = factoryDeptCode;
          this.form.factoryDeptId = factoryDeptId;
          this.form.workshopCode = workshopCode;
          this.form.workshopId = workshopId;
          this.form.lineId = lineId ? lineId : this.form.lineId;
          this.form.erpProductionLineCode = lineCode ? lineCode : this.form.erpProductionLineCode;
          this.form.equipmentCode = equipCode ? equipCode : this.form.equipmentCode;
          this.form.equipmentName = equipName ? equipName : this.form.equipmentName;
        } else {
          this.resetFormData()
        }
      }).catch(() => {
        this.resetFormData()
      })
    },

    //忽略异常
    handleIgnore(){
      this.$refs.ruleForm
      .validate((flag) => {
        if (flag) {
          this.$confirm("确定忽略此条异常上报？", "异常忽略", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
          }).then(() => {
            distributeIgnore({id:this.row.id,checkDes:this.form.checkDes})
          }).then(() => {
            this.$emit("submit-success")
            this.dialogVisible = false;
          }).catch(() => {
          });
        }
        else {
          this.saveloading = false
        }
      })
    },

    //转为异常
    convertToAbnormal(){
      this.$refs.ruleForm
      .validate((flag) => {
        if (flag) {
          this.detailDialog.row = this.row;
          this.detailDialog.row.checkDes = this.form.checkDes;
          this.detailDialog.visible = true;
        }else {
          this.saveloading = false
        }
      })
    },

    //确定上报，下发
    handleSubmit() {
      this.saveloading = true;
      let msg = "";
      let title = "";
      if(this.mode == "report"){
        msg = "确定提交此条上报异常？";
        title = "异常上报";
        this.form.orderType = "1";
      }
      else if(this.mode == "distribute"){
        msg = "确定提交此条下发异常？";
        title = "异常下发";
        this.form.orderType = "2";
      }
      this.$refs.ruleForm
      .validate((flag) => {
        if (flag) {
          this.$confirm(msg, title, {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
          }).then(() => {
            // this.$emit("submitOperate",this.form);
            this.submitOperate()
          }).catch(() => {});
        } else {
          this.saveloading = false
        }
      })
    },

    submitOperate() {
      this.saveloading = true;
      abnormalAddOrUpdate(this.form).then(res => {
        if (res.code == 200) {
          this.msgSuccess("操作成功")
          this.$emit("submit-success");
          this.dialogVisible = false;
        } else {
          this.msgError(res.msg || "操作失败")
        }
        this.saveloading = false
      }).catch(() => {
        this.msgError("操作失败")
        this.saveloading = false
      })
    },

     //取消上报，下发
    handleCancel(){
      let msg = "";
      let title = "";
      if(this.mode == "report"){
        msg = "确定取消上报并离开当前页面？已填写的内容将会丢失？";
        title = "异常上报"
      }
      else if(this.mode == "distribute"){
        msg = "确定取消下发并离开当前页面？已填写的内容将会丢失";
        title = "取消下发"
      }
      this.$confirm(msg, title, {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
      }).then(() => {
         this.dialogVisible = false;
      }).catch(() => {

      });
    },

    //打开人员选择器
    openUserDialog(key) {
      this.userDialog.defaulSelectUsers = [];
      this.userDialog.branchinnercode = this.baseDeptId;
      this.userDialog.key = key;
      if(key == "processedName"){//责任人
        let processedUserList = this.form.processedUserName && this.form.processedUserName.split(",");
        let processedNameList = this.form.processedName && this.form.processedName.split(",");
        if(processedUserList?.length){
          processedUserList.forEach((item,index) => {
            this.userDialog.defaulSelectUsers.push({
              username:item,
              realname:processedNameList[index]
            })
          })
        }
      }
      else if(key == "checkName"){
        let checkUserList = this.form.checkUserName  && this.form.checkUserName.split(",");
        let checkNameList = this.form.checkName && this.form.checkName.split(",");
        if(checkUserList?.length){
          checkUserList.forEach((item,index) => {
            this.userDialog.defaulSelectUsers.push({
              username:item,
              realname:checkNameList[index]
            })
          })
        }
      }
      this.userDialog.visible = true;
    },

    closeUserDialog(list){
      if(list?.length){
        if(this.userDialog.key == "processedName"){
          this.form.processedUserName = list.map(item => item.username).join();
          this.form.processedName = list.map(item => item.realname).join();
        }
        else if(this.userDialog.key == "checkName"){
          this.form.checkUserName = list.map(item => item.username).join();
          this.form.checkName = list.map(item => item.realname).join();
        }
      }else{
        if(this.userDialog.key == "processedName"){
          this.form.processedUserName = "";
          this.form.processedName = "";
        }
        else if(this.userDialog.key == "checkName"){
          this.form.checkUserName = "";
          this.form.checkName = "";
        }
      }
    },

    // 打开设备列表
    openEquipDialog() {
      const { equipmentName, equipmentCode } = this.form;
      if (equipmentCode) {
        this.equipListDialog.defaultValues = [
          {
            equipCode: equipmentCode,
            equipName:equipmentName,
            id:this.deviceId
          },
        ];
      }else{
        this.equipListDialog.defaultValues = [];
      }
      this.equipListDialog.visible = true;
    },

    // 关闭设备列表
    closeEquipDialog(list) {
      if (!list?.length) {
        this.form.equipmentCode = null;
        this.form.equipmentName = null;
        return
      }
      this.form.equipmentCode = list[0].equipCode;
      this.form.equipmentName = list[0].equipName;
      this.deviceId = list[0].id;
    },

    openIndexDialog() {
      this.indexDialog.defaultValues = [];
      if(this.form.indexCode){
        this.indexDialog.defaultValues.push({
          id:this.form.indexCode,
          indexConfigName:this.form.indexName
        })
      }
      this.indexDialog.visible = true
    },

    closeIndexDialog(list) {
      if(list?.length){
        const indexItem = list[0]
        const {indexType} = indexItem?.indexMetaDto;
        const {
            factoryDeptCode,
            factoryDeptId,
            workshopCode,
            workshopId,
            lineCode,
            lineId,
            equipCode,
            equipName,
            id,
            indexConfigName
        } = indexItem;
        this.form.indexCode = id;
        this.form.indexName = indexConfigName;
        this.form.indexType = indexType;
        this.form.indexTypeName = indexType ? this.indexTypeDictMap[indexType] : null;
        this.form.factoryDeptCode = factoryDeptCode;
        this.form.factoryDeptId = factoryDeptId;
        this.form.workshopCode = workshopCode;
        this.form.workshopId = workshopId;
        this.form.lineId = lineId;
        if(this.form?.factoryDeptCode){
          this.handleFactory(this.form.factoryDeptCode,"init")
        }
        if(this.form?.workshopCode){
          this.handleWorkshop(this.form.workshopCode,"init")
        }
        this.form.erpProductionLineCode = lineCode;
        this.form.equipmentCode = equipCode;
        this.form.equipmentName = equipName;
        this.indexItem = {
          indexType,
          factoryDeptCode,
          workshopCode,
          erpProductionLineCode:lineCode,
          equipmentName:equipName
        }
      }else{
        this.form.indexCode = null
        this.form.indexName = null;
        this.form.indexType = null;
        this.form.indexTypeName = null;
        this.form.abnormalUnit = null;
        this.form.warmUnit = null;
        this.form.indexOrganization = null;
        this.form.factoryDeptName = null;
        this.form.factoryDeptCode = null;
        this.form.workshopName = null;
        this.form.workshopCode = null;
        this.form.workshopId = null;
        this.form.lineName = null;
        this.form.lineId = null;
        this.form.erpProductionLineCode = null;
        this.form.equipmentCode = null;
        this.form.equipmentName = null;
        this.indexItem.indexType = null;
        this.indexItem.factoryDeptCode = null;
        this.indexItem.workshopCode = null;
        this.indexItem.erpProductionLineCode = null;
        this.indexItem.equipmentName = null;
      }
    },

    callbackDialog(){
      this.$emit("submit-success")
      this.dialogVisible = false;
    },

    //选择工厂,获取车间数据
    handleFactory(val,type){
      if(!type){
        this.form.workshopCode = null;
        this.form.workshopId = null;
        this.form.erpProductionLineCode = null;
        this.form.lineId = null;
      }
      const factoryItem = this.allList.find(ele => ele.factoryDeptCode === val);
      this.workshopList = factoryItem?.workshopVos ? factoryItem?.workshopVos : [];
      this.form.factoryDeptId = factoryItem?.factoryDeptId
    },

    //选择车间,获取产线数据
    handleWorkshop(val,type){
      if(!type){
        this.form.erpProductionLineCode = null;
        this.form.lineId = null;
      }
      const workshopItem = this.workshopList.find(ele => ele.workshopCode === val);
      this.lineList = workshopItem?.productionLineVos ? workshopItem?.productionLineVos : [];
      this.form.workshopId = workshopItem?.workshopId
    },

    handleLine(val){
      const lineItem = this.lineList.find(ele => ele.lineCode === val);
      this.form.lineId = lineItem?.lineId
    },

    handleSuccess(response, file, fileList){
      this.fileList = fileList;
      this.form.fileIds = fileList.map(ele => ele.response?.data)
    },

    handleRemove(file, fileList) {
      this.fileList = fileList;
      if(fileList?.length){
        this.form.fileIds = fileList.map(ele => ele.response?.data)
      }else{
        this.form.fileIds = []
      }
    },

    handlePreview(file) {
      axios({
        baseURL:service.baseURL + GEN_SERVER['form-server'],
        url:'/refine/report/byte/down',
        method:"get",
        params:{id:file.response.data},
        headers: {Authorization:'Bearer ' + getToken()},
        responseType: 'blob'
      }).then(res => {
        let count = file.name.lastIndexOf(".");
        let fileName = file.name.slice(0,count);
        let suffix = file.name.slice(count);
        downloadFile(res.data,`${fileName}${parseTime(new Date(), '{y}{m}{d}')}${suffix}`)
        this.saveloading = false
      }).catch(() => {
        this.msgError("操作失败")
        this.saveloading = false
      })
    },

    beforeAvatarUpload(file){
      if(!this.acceptFile.includes(file.type)){
        this.msgWarning("暂不支持上传该格式文件");
        return false
      }
      if(file.size / 1024 / 1024  > 5){
        this.msgWarning("上传的附件大小不得超过5M");
        return false
      }
    },

    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 10个文件，本次选择了 ${files.length} 个文件`);
      return false
    },

    resetFormData() {
      this.form = {
        orderName:null,
        abnormalLevelCode:null,
        abnormalTypeCode:null,
        indexCode:null,
        indexType:null,
        indexTypeName:null,
        factoryDeptCode:null,
        workshopCode:null,
        erpProductionLineCode:null,
        equipmentCode:null,
        equipmentName:null,
        reportName:null,
        reportUserName:null,
        checkName:null,
        checkUserName :null,
        processedUserName:null,
        processedName:null,
        checkDes:null,
        fileIds:[]
      };
      this.fileList = [];
      this.indexItem ={
        indexType:null,
        factoryDeptCode:null,
        workshopCode:null,
        erpProductionLineCode:null,
        equipmentName:null
      };
      this.$refs.ruleForm?.resetFields();
    },
  },
};
</script>
<style lang="scss" scoped>
.el-form {
  display: flex;
  justify-content: space-between;
  flex-flow: wrap;
  .el-form-item {
    width: 49%;
  }
  .el-date-editor.el-input,
  .el-select {
    width: 100%;
  }
}
// ::v-deep.dialog-report-dis{
//   .el-dialog {
//     .el-dialog__body{
//       max-height: calc(100vh - 11rem);
//     }
//   }
// }

</style>
